#include <iostream>
using namespace std;

int bottle(int bottle)
{
    int exchange;
    int leave;
    int sum = 0;

    exchange = bottle / 3;
    leave = bottle % 3;
    sum += exchange;

    while (1)
    {
        bottle = exchange + leave;
        exchange = bottle / 3;
        leave = bottle % 3;
        sum += exchange;
        if(exchange + leave == 2){
            sum +=1;
            break;
        }else if(exchange + leave == 1){
            break;
        }
    }
    return sum;
}

int main(int agrc, char **agrv)
{
    int num;
    int res;
    while (cin >> num)
    {
        if (num == 0)
            continue;
        res = bottle(num);
        cout << res << endl;
    }
    return 0;
}